package com.javen.jnet;

import android.app.Application;
import android.test.ApplicationTestCase;

import com.squareup.okhttp.MediaType;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.RequestBody;
import com.squareup.okhttp.Response;

import org.json.JSONObject;

import java.io.IOException;
import java.util.HashMap;

import okio.BufferedSink;

/**
 * <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
 */
public class ApplicationTest extends ApplicationTestCase<Application> {
    public ApplicationTest() {
        super(Application.class);
    }

    public void testA() throws IOException {
        Response response = OkHttpClient.newClient().newCall(new Request.Builder().url("http://www.baidu.com").setHeaders(new HashMap<String, String>()).post(new RequestBody() {
            @Override
            public MediaType contentType() {
                return null;
            }

            @Override
            public void writeTo(BufferedSink sink) throws IOException {

            }
        }).build()).execute();

        if (response.isSuccessful()) {
            JSONObject obj = response.body().getJSONObject();
            System.out.println(obj);
        }

    }
}